package com.iory.tianwangterminator;


import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import com.iory.db.TianwangSqliteHelper;



import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.VideoView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

public class MainActivity extends ListActivity {

	private static final String[] TYPE_DATA = {"四川", "广东","网络电视"};
	
	
	private ArrayList<HashMap<String,Object>>  mCateData;
	SimpleAdapter mListAdapter;
	ListView mListView;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		TianwangConst.setInstanceContext(this);
		//requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);
		mListView = getListView();
		initListAdapter();
		
		 TianwangSqliteHelper dbHelper = new TianwangSqliteHelper(this);
	        try {
				dbHelper.createDataBase();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

	}

	private void initListAdapter() {
		//getDraftData();
		mCateData = new ArrayList<HashMap<String, Object>>();
		for(int i=0;i<3;i++)   
		{
			HashMap<String, Object> map = new HashMap<String, Object>(); 
			if(i<2){
				map.put("icon", R.drawable.camera); 
			}
			else{
				map.put("icon", R.drawable.tv); 
			}
		    map.put("name", TYPE_DATA[i]);
	        map.put("arrow", R.drawable.arrow);   
	        mCateData.add(map);
		}
		mListAdapter = new SimpleAdapter(this,mCateData,  
	            R.layout.main_listitem,      
	            new String[] {"icon","name", "arrow"},     
	            new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.item_arrow}   
	        );   
	                
	 mListView.setAdapter(mListAdapter);   

	 mListView.setOnItemClickListener(new OnItemClickListener() {   
	  @Override  
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {   
			Intent intent = new Intent (MainActivity.this, ProvinceActivity.class);
			Bundle bund = new Bundle();
			bund.putString("TypeName", mCateData.get(arg2).get("name").toString());
			intent.putExtras(bund);
			startActivity(intent);
        }   
    });
	}
	
	




}
